import java.awt.*;  
import java.awt.datatransfer.*;  
   
class BoardListener extends Thread implements ClipboardOwner {  
  Clipboard sysClip = Toolkit.getDefaultToolkit().getSystemClipboard();  
  
  public void run() {  
    Transferable trans = sysClip.getContents(this);  
    regainOwnership(trans);  
    System.out.println("Listening to board...");  
    while(true) { try { sleep(10); } catch (InterruptedException e) {
		e.printStackTrace();
	} }  
  }  
   
  public void lostOwnership(Clipboard c, Transferable t) {
	try { sleep(50); } catch (InterruptedException e) {
		e.printStackTrace();
	}
    Transferable contents = sysClip.getContents(this);  
    processContents(contents);  
    regainOwnership(contents);  
  }  
   
  void processContents(Transferable t) {  
    System.out.println("Processing: " + t);  
  }  
   
  void regainOwnership(Transferable t) {  
    sysClip.setContents(t, this);  
  }  
} 